package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class SetmealController {


    @Autowired
    private SetmealService setmealService;


    // 套餐列表 分页
    @GetMapping("/setmeal/page")
    public ResultInfo findByPage(@RequestParam(name = "page",defaultValue = "1")  Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,String name){
       //调用service
        Page<Setmeal> page = setmealService.findByPage(pageNum,pageSize,name);
        //返回结果
        return ResultInfo.success(page);
    }


    // 新增套餐
    @PostMapping("/setmeal")
    public ResultInfo save(@RequestBody Setmeal setmeal) {
        // 调用service新增
        setmealService.save(setmeal);
        // 返回结果
        return ResultInfo.success();
    }



    // 删除套餐
    @DeleteMapping("/setmeal")
    public ResultInfo deleteBatch(@RequestParam List<Long> ids) {
        // 调用service删除
        setmealService.deleteBatch(ids);
        // 返回结果
        return ResultInfo.success();
    }


}
